﻿; window.ZbTemplet = window.ZbTemplet || {};
window.ZbTemplet.UEditFrame = `
<div>
    <script :id="uniquedId" type="text/plain"></script>
</div>
`;

if (!Array.prototype.find) {
    Array.prototype.find = function (callback) {
        return callback && (this.filter(callback) || [])[0];
    };
}

Vue.component('zb-ueditor', {
    template: window.ZbTemplet.UEditFrame
    , data() {
        return {
            uniquedId: 'uniqueid_' + Math.random() * 10000000000000
            , instance: null
        }
    }
    , mounted: function () {
        this.initEditor();
    }
    , props: ['value']
    , watch: {
        value: function (newVal, oldVal) {
            console.log(newVal, oldVal);
            if (this.instance) {
                this.instance.setContent(newVal || '');
            }
        }
    }
    , methods: {
        initEditor: function () {
            const me = this;
            me.instance = UE.getEditor(me.uniquedId);
            me.instance.ready(function () {
                me.instance.setContent(me.value || '');
            });
        }
    }
});